package com.landian.commons.base.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Collection;

/**
 * @author caojl
 * @date: 2018-08-21
 * @time: 22:30
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class PageDTO<T> implements Serializable {

    /**
     * 数据
     */
    private Collection<T> data;

    /**
     * 当前分页
     */
    private Integer currentPage;

    /**
     * 分页大小
     */
    private Integer pageSize;

    /**
     * 总页数
     */
    private Integer totalPage;

    /**
     * 总数
     */
    private Integer totalRows;

    public static <T> PageDTO<T> newInstance(int currentPage, int pageSize, int totalRows, Collection<T> data){
        int totalPage = (totalRows  +  pageSize  - 1) / pageSize;
        return new PageDTO(data, currentPage, pageSize, totalPage, totalRows);
    }
}
